package gui.beans;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.toedter.calendar.JCalendar;

import datos.ControlHoras;

import gui.eventos.ChangeDateEvent;
import gui.eventos.ChangeDateListener;

@SuppressWarnings("serial")
public class MyCalendar extends JCalendar {

	List<ChangeDateListener> listeners = null;

	public void propertyChange(PropertyChangeEvent evt) {
		super.propertyChange(evt);
		fireChangeDateEvent();
	}

	public String getStringDate(){
		return ControlHoras.df.format(getDate());
	}
	
	public void addChangeDateListener(ChangeDateListener listener) {
		if (listeners == null)
			listeners = new ArrayList<ChangeDateListener>();
		listeners.add(listener);
	}

	public void fireChangeDateEvent() {
		ChangeDateEvent e = new ChangeDateEvent(this, ControlHoras.df.format(getDate()), getDate());
		if (listeners == null)
			return;
		Iterator<ChangeDateListener> i = listeners.iterator();
		while (i.hasNext()) {
			i.next().dateChanged(e);
		}
	}
}
